﻿using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {
    public int HP=10;
    GameObject deadPrefab;
    public static GameObject weapon;
    public static GameObject protact;
    public static GameObject life;
    
    private void Awake()
    {
        deadPrefab = Resources.Load<GameObject>("Fx/Boom");
        weapon = Resources.Load<GameObject>("Props/weapon_Prop");
        protact = Resources.Load<GameObject>("Props/Protact_Prop");
        life = Resources.Load<GameObject>("Props/life_Prop");
        
    }
public void OnDamage(int damage)
    {
        if (HP>0)
        {
            HP -= damage;
            if (HP <= 0)
            {
                int number = Random.Range(0, 20);
                switch (number)
                {
                    case 0:
                        GameObject goo = Instantiate(weapon);
                        goo.transform.position = transform.position;
                        break;
                    case 1:
                        GameObject gooo = Instantiate(protact);
                        gooo.transform.position = transform.position;
                        break;
                    case 2:
                        GameObject goooo = Instantiate(life);
                        goooo.transform.position = transform.position;
                        break;
                    default:
                        break;
                }
                GameObject go = GameObject.Instantiate(deadPrefab);
                go.transform.position = transform.position;
                Destroy(go, 0.42f);
                Destroy(gameObject);
            }
        }
        
    }
}
